package eu.boss.model;

import java.io.Serializable;
import java.text.DecimalFormat;

import org.codehaus.jackson.annotate.JsonIgnore;

public class Team implements Serializable, Comparable<Object>{

	private static final long serialVersionUID = -655358114861514295L;

	private TeamType team;
	private int wins;
	private int losts;
	
	public Team() {}

	@JsonIgnore
	public Team(TeamType team, int won, int lost) {
		super();
		this.team = team;
		this.wins = won;
		this.losts = lost;
	}		
	
	public TeamType getTeam() {
		return team;
	}

	public void setTeam(TeamType team) {
		this.team = team;
	}

	public int getWins() {
		return wins;
	}

	public void setWins(int wins) {
		this.wins = wins;
	}

	public int getLosts() {
		return losts;
	}

	public void setLosts(int losts) {
		this.losts = losts;
	}

	/**
	 * All of the following methods are ignored during the serialization/deserialization
	 */
	
	@JsonIgnore
	public void incrementWin(){
		wins++;
	}
	@JsonIgnore
	public void incrementLost(){
		losts++;
	}
	
	
	
	@JsonIgnore
	public String getRatio(){
		DecimalFormat DEC = new DecimalFormat("0.00");
		float res;
		float wins=(float)(getWins());
		float losts=(float)(getLosts());
		if (getWins()+getLosts()==0)
			res=0;
		else
		res= wins/(wins+losts);
		return DEC.format(res);	
	}
	
	@JsonIgnore
	/**
	 * Used to sort list by ratio
	 */
	public int compareTo(Object o1) {
		if(!(o1 instanceof Player))
	        throw new ClassCastException();
	        return (((Team)o1).getRatio()).compareTo((this.getRatio()));
	}
	
	@JsonIgnore
	public void reInit(){
		this.wins=0;
		this.losts=0;
	}
}
